<?php
function _ctlMenu($name, $attribs)
{
	$cacheId = 'WebControl.DynamicMenu.' . $name;
	if (defined('DEPLOY_MODE') && DEPLOY_MODE) {
	    $lifetime = 900;
	} else {
	    $lifetime = 0;
	}
	$rowset = FLEA::getCache($cacheId, $lifetime);
	if (!$rowset) {

		FLEA::writeCache($cacheId, $rowset);
	}

    $acl = FLEA::loadFile('Config_DefaultACT.php');
    $menuconfig = FLEA::loadFile('Config_MenuConfig.php');
	$dispatcher =& FLEA::getSingleton(FLEA::getAppInf('dispatcher'));
    $data = array();
    foreach($menuconfig as $m => $n){
        foreach ($n as $key => $value){
            foreach($value as $k => $v){
                if($dispatcher->check($key, $k)) {
                    $data[$m][$v] = url($key,$k);
                }
            }
        }
    }
    unset($menuconfig);
    $str = "{var nav_menu = [\n";
    foreach($data as $key => $value){
        if(is_array($value)){
            $str .= "[null,'".$key."',null,null,null,";
            foreach($value as $k => $v){
                $str .="[null,'".$k."','".$v."',null,null],";
            }
            $str .= "],\n";
        }
        else{
            $str .= "[null,'".$key."','".$value."',null,null],\n";
        }
    }
    $str .="];}";
    $smarty = FLEA::getSingleton(FLEA::getAppInf('view'));
    $smarty->assign('output', $str);
    $smarty->assign('menu_name', $name);
    return $smarty->fetch('webcontrols/menu.html');
}
